package com.xiaotu.dao.mysql;

import com.xiaotu.entity.ActorAwardModel;
import com.xiaotu.entity.StarDeleteRecordModel;
import com.xiaotu.entity.StarModel;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.BaseMapper;

import java.util.List;

/**
 * @author zhangxiao
 * @create 2021-09-23 9:07
 */
public interface MysqlStarMapper extends BaseMapper<StarModel> {

    @Select("<script>" +
            " SELECT starid FROM screenwriter.tab_star_info WHERE starid IN ( " +
            " <foreach collection='starids' separator=',' item='v'> " +
            " #{v} " +
            " </foreach> " +
            " ) " +
            "</script>")
    List<Integer> isExist(@Param("starids") List<Integer> starids);

    @Insert("<script>" +
            " INSERT INTO `screenwriter`.`tab_star_info`( " +
            " `starid`, `name`, `alias`, `occupation`," +
            " `country`, `area`, `sex`, `height`," +
            " `weight`, `bloodtype`, `nation`, `school`," +
            " `born`, `birthday`, `constellation`, `interest`," +
            " `introduction`, `brokeragefirm`, `works`, `awards`," +
            " `imagesurl`, `createtime`, `lastupdatetime`, `starnameid`," +
            " `dataweight`, `representativework`, `representativeworkid`, `uniquename`," +
            " `repeat`, `weibourl`, `agent`, `agentphone`," +
            " `label`, `datastate`, `datasourceid`, `deathday`, `foreignersign`, baikeurl, doubanurl)" +
            "  VALUES " +
            " <foreach collection='list' separator=',' item='v' > " +
            " (#{v.starid}, #{v.name}, #{v.alias}, #{v.occupation}," +
            " #{v.country}, #{v.area}, #{v.sex}, #{v.height}," +
            " #{v.weight}, #{v.bloodtype}, #{v.nation}, #{v.school}," +
            " #{v.born}, #{v.birthday}, #{v.constellation}, #{v.interest}," +
            " #{v.introduction}, #{v.brokeragefirm}, #{v.works}, #{v.awards}," +
            " #{v.imagesurl}, #{v.createtime}, #{v.lastupdatetime}, #{v.starnameid}," +
            " #{v.dataweight}, #{v.representativework}, #{v.representativeworkid}, #{v.uniquename}," +
            " #{v.repeat}, #{v.weibourl}, #{v.agent}, #{v.agentphone}," +
            " #{v.label}, #{v.datastate}, #{v.datasourceid}, #{v.deathday}, #{v.foreignersign},#{v.baikeurl},#{v.doubanurl}) " +
            " </foreach> " +
            "</script>")
    void batchInsert(@Param("list") List<StarModel> insertMysqlList);

    @Update("<script>" +
            " <foreach collection='list' item='v' > " +
            " UPDATE `screenwriter`.`tab_star_info` SET " +
            " `name` = #{v.name}, `alias` = #{v.alias}, `occupation` = #{v.occupation}, `country` = #{v.country}," +
            " `area` = #{v.area}, `sex` = #{v.sex}, `height` = #{v.height}, `weight` = #{v.weight}," +
            " `bloodtype` = #{v.bloodtype}, `nation` = #{v.nation}, `school` = #{v.school}, `born` = #{v.born}," +
            " `birthday` = #{v.birthday}, `constellation` = #{v.constellation}, `interest` = #{v.interest}, `introduction` = #{v.introduction}," +
            " `brokeragefirm` = #{v.brokeragefirm}, `works` = #{v.works}, `awards` = #{v.awards}, `imagesurl` = #{v.imagesurl}," +
            " `createtime` = #{v.createtime}, `lastupdatetime` = #{v.lastupdatetime}, `starnameid` = #{v.starnameid}, `dataweight` = #{v.dataweight}," +
            " `representativework` = #{v.representativework}, `representativeworkid` = #{v.representativeworkid}, `uniquename` = #{v.uniquename}, `repeat` = #{v.repeat}," +
            " `weibourl` = #{v.weibourl}, `agent` = #{v.agent}, `agentphone` = #{v.agentphone}, `label` = #{v.label}," +
            " `datastate` = #{v.datastate}, `datasourceid` = #{v.datasourceid}, `deathday` = #{v.deathday}, `foreignersign` = #{v.foreignersign}," +
            "  baikeurl = #{v.baikeurl},doubanurl = #{v.doubanurl} " +
            "  WHERE `starid` = #{v.starid} ; " +
            " </foreach> " +
            "</script>")
    void batchUpdate(@Param("list") List<StarModel> updateMysqlList);

    @Delete("<script>" +
            " DELETE FROM screenwriter.tab_actor_award " +
            "</script>")
    void clearStarAwards();

    @Insert("<script>" +
            " INSERT INTO `screenwriter`.`tab_actor_award`" +
            " (id,`starid`, `award_time`, `award_type`, `award_section`," +
            " `award_role`, `award_nominate`, `collect_time`)" +
            " VALUES " +
            " <foreach collection='list' separator=',' item='v' > " +
            " (#{v.id},#{v.star_id}, #{v.award_time}, #{v.award_type}, #{v.award_section}," +
            " #{v.award_role}, #{v.award_nominate}, #{v.collect_time}) " +
            " </foreach> " +
            "</script>")
    void batchInsertStarAwards(@Param("list") List<ActorAwardModel> actorAwardModels);

    @Insert("<script>" +
            " INSERT INTO `screenwriter`.`tab_star_delete_record`" +
            " (`starid`, `starname`, `deletereason`, `deletetime`, `lastupdatetime`) " +
            " VALUES " +
            " <foreach collection='list' separator=',' item='v' > " +
            " (#{v.starid}, #{v.starname}, #{v.deletereason}, #{v.deletetime}, #{v.lastupdatetime}) " +
            " </foreach> " +
            "</script>")
    void batchInsertDeleteRecord(@Param("list") List<StarDeleteRecordModel> list);

    @Delete(" DELETE FROM `screenwriter`.`tab_star_delete_record` ")
    void clearDeleteRecord();

    @Delete(" DELETE screenwriter.tab_star_info " +
            "FROM  " +
            "  screenwriter.tab_star_info " +
            "  INNER JOIN ( SELECT t1.starid FROM screenwriter.tab_star_info t1 INNER JOIN screenwriter.tab_star_delete_record t2 ON t1.starid = t2.starid ) t4 ON screenwriter.tab_star_info.starid = t4.starid; ")
    void deleteNoUseStar();
}
